package com.sky.service.adminImpl;

import com.sky.exception.ShopStatusException;
import com.sky.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import static com.sky.constant.MessageConstant.SHOP_STATUS_EXCEPTION;

@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Override
    public void changeStatus(Integer status) {
        ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();
        operations.set("SHOP_STATUS", String.valueOf(status));
    }

    @Override
    public Integer getStatus() {
        ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();
        String s = operations.get("SHOP_STATUS");
        if (s != null) {
            return Integer.valueOf(s);
        }
        throw new ShopStatusException(SHOP_STATUS_EXCEPTION);
    }
}
